/*
 * @Author: your name
 * @Date: 2020-10-08 17:08:27
 * @LastEditTime: 2021-03-01 15:41:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\router\index.js
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import yhRouter from './index_yh'
import wdRouter from './index_wd'

Vue.use(VueRouter)
const routes = [
    { path: "/", redirect: "/login" },
    { //远程设置
        path: '/index',
        name: 'indexSet',
        component: () =>
            import ('../views/login/login.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ( /* webpackChunkName: "login" */ '../views/login/login.vue')
    }, {
        path: '/register',
        name: 'register',
        component: () =>
            import ( /* webpackChunkName: "register" */ '../views/register/register.vue')
    }, {
        path: '/passwordReset',
        name: 'register',
        component: () =>
            import ( /* webpackChunkName: "register" */ '../views/passwordReset/index.vue')
    }, {
        path: '/warranty',
        name: 'warranty',
        component: () =>
            import ( /* webpackChunkName: "warranty" */ '../views/warranty/warranty.vue')
    }, {
        path: '/installationGuide',
        name: 'installationGuide',
        component: () =>
            import ( /* webpackChunkName: "installationGuide" */ '../views/installationGuide/index.vue')
    }, {
        path: '/installationGuide/installation',
        name: 'installation',
        component: () =>
            import ( /* webpackChunkName: "installationGuide" */ '../views/installationGuide/installation.vue')
    }, {
        path: '/installationGuide/explain',
        name: 'explain',
        component: () =>
            import ( /* webpackChunkName: "installationGuide" */ '../views/installationGuide/explain.vue')
    }, {
        path: '/overview-inverter',
        name: 'overviewInverter',
        component: () =>
            import ( /* webpackChunkName: "overviewInverter" */ '../views/overview-inverter/overview-inverter.vue')
    }, {
        path: '/overview_site',
        name: 'overview_site',
        component: () =>
            import ( /* webpackChunkName: "overviewSite" */ '../views/overview/overview_site.vue')
    }, {
        path: '/exampleSite',
        name: 'exampleSite',
        component: () =>
            import ( /* webpackChunkName: "overviewInverter" */ '../views/overview-inverter/exampleSite.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () =>
            import ( /* webpackChunkName: "home" */ '../views/Home.vue'),
        children: [...yhRouter, ...wdRouter,
            {
                path: '/refresh',
                name: 'refresh',
                component: () =>
                    import ('../views/refresh.vue')
            }, {
                path: '/404', // 页面不存在的情况下会跳到404页面 @@@@该路由放在最下面
                name: 'notFound',
                component: () =>
                    import ( /* webpackChunkName: "404" */ '../views/404/index.vue')
            }
        ]
    },
    {
        path: '/payReturn',
        name: 'payReturn',
        component: () =>
            import ( /* webpackChunkName: "payReturn" */ '../views/insurancePay/payReturn.vue')
    },
    {
        path: '/payReturnError',
        name: 'payReturnError',
        component: () =>
            import ( /* webpackChunkName: "payReturn" */ '../views/insurancePay/payReturnError.vue')
    }, {
        path: '*', // 页面不存在的情况下会跳到404页面 @@@@该路由放在最下面
        name: 'notFound',
        redirect: '/404',
    }

]

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
        if (to.path == '/') {
            next('/login');
            return
        }
        //设置拦截--远程设置菜单转跳
        if (to.path == '/index') {
            window.open(window.location.href.split('#')[0] + 'settingNew/index.html', '', 'width=400,height=640,top=50, left=400, toolbar=no, menubar=no, scrollbars=no,location=no,help=off;resizable=off;scroll=no;status=off')
            return
        }
        next();
    })
    /**
     * 跳转登陆页面强制刷新，相当于F5
     */
router.afterEach((to, from) => {
    if (from.path != '/Login' && from.path != '/' && to.path == '/Login') {
        window.location.reload();
    }
})

export default router